package com.xsz.service;



import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

<<<<<<< HEAD
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.xsz.dto.ArticleDTO;
import com.xsz.entity.Blog;
import com.xsz.entity.BlogTag;
import com.xsz.repository.BlogRepository;
import com.xsz.repository.BlogTagRepository;
import com.xsz.repository.TagRepository;
=======
import org.springframework.stereotype.Service;

import com.xsz.entity.Blog;
import com.xsz.repository.BlogRepository;
>>>>>>> f02232e15acf256ce9318fb7b78caf2ab4fad356
import com.xsz.util.KeyUtil;

@Service
public class BlogService {
	@Resource
	BlogRepository blogRepository;
<<<<<<< HEAD
	@Resource
	BlogTagRepository blogtagRepository;
	public Blog add(ArticleDTO adto) {
		Blog blog=new Blog();
		BeanUtils.copyProperties(adto,blog);
		String blogId=KeyUtil.getId();
		blog.setId(blogId);
		blog.setCreateTime(new Date());
		blog.setModifyTime(new Date());
		adto.getTags().forEach(e->{
			BlogTag bt=new BlogTag();
			bt.setId(KeyUtil.getId());
			bt.setBlogId(blogId);
			bt.setTagId(e.getId());
			blogtagRepository.save(bt);
		});
=======
	
	public Blog add(Blog blog) {
		blog.setId(KeyUtil.getId());
		blog.setCreateTime(new Date());
		blog.setModifyTime(new Date());
>>>>>>> f02232e15acf256ce9318fb7b78caf2ab4fad356
		return blogRepository.save(blog);
	}
	
	public Blog update(Blog blog) {
		blog.setModifyTime(new Date());
		return blogRepository.save(blog);
	}
	
	public void delete(String id) {
		blogRepository.deleteById(id);
	}
	
	public Blog selectById(String id) {
		return blogRepository.findById(id).get();
	}
<<<<<<< HEAD
	//查询博客
	public Blog selectByTitle(String title) {
		return blogRepository.findByTitleAndStatus(title, 0);
	}
	//查询博客
	public List<Blog> selectByAuthor(String author) {
		return blogRepository.findByAuthorAndStatus(author, 0);
	}
	//查询作者的草稿博客
		public List<Blog> selectByAuthor2(String author) {
			return blogRepository.findByAuthorAndStatus(author, 1);
		}
=======
	
	public Blog selectByTitle(String title) {
		return blogRepository.findByTitle(title);
	}
	
	public List<Blog> selectByAuthor(String author) {
		return blogRepository.findByAuthor(author);
	}
>>>>>>> f02232e15acf256ce9318fb7b78caf2ab4fad356
}
